<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="${staticServer}/inc/style/main.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/page.css" />
<link rel="stylesheet" href="${staticServer}/css/struct_info.css" />
<script src="${staticServer}/inc/js/jquery.js"></script>
<script src="${staticServer}/inc/js/pageset.js"></script>
<script src="${staticServer}/inc/js/submitter.js"></script>
<script src="${staticServer}/inc/js/infopad.js?2.2"></script>
<script type="text/javascript" src="${staticServer}/common/uploadify/jquery.uploadify.js"></script>
<link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css" />
<script src="${staticServer}/inc/js/datepicker.js"></script>

<style type="text/css">
#SWFUpload_0{
	margin-top: 10px;
    margin-left: -30px;
}
#upis {
    background-color: #4CAF50; /* Green */
    border: 5px;
    border-radius: 5px;
    color: white;
    padding: 5px 5px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
}
#upis_solve {
    background-color: #4CAF50; /* Green */
    border: 5px;
    border-radius: 5px;
    color: white;
    padding: 5px 5px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
}
</style>
<script>
var contextPath='${contextPath}';
var _contextPath = '${staticServer}';

$(function(){
	//页面加载记录选择器值
	//如果之前有值从之前的算起
	var  bcount = $("#bcount").val();
	var bc = Number(bcount)
	if(bc>0 && countAry.length==1){
		count = bcount
		
		for (var j = 1;j<count; ){
			var tt = ++j
			
			countAry.push(tt);	
		}	
	}
	//如果没有从1开始

	$("#firstO").nextAll().remove();
	//$("#ac").empty();
	for (i in countAry) {
		var tt = ++i;
		$("#ac").append("<option value="+i+">" + "事件" + tt + "</option>")
	}
	
	$("#center_id").val("<#if inspection??>${inspection.center_id}</#if>");
	$("#inspection_time").val("<#if inspection??>${inspection.inspection_time}</#if>");
	$("#solve_state").val("<#if inspection??>${inspection.solve_state}</#if>");
	$("#problem_find").val("<#if inspection??>${inspection.problem_find}</#if>");
	$("#problem_solve").val("<#if inspection??>${inspection.problem_solve}</#if>");
	$("#inspection_time").val("<#if inspection??>${inspection.inspection_time}</#if>");
	if($("#id").val() != null && $("#id").val() != ""){
		$("#inspection_time").attr("disabled",true);
		$("#center_id").attr("disabled",true);
		
	}
	if($("#isScan").val() == 1){
		$("#foot").hide();
		$("textArea").attr("disabled",true);
	}
	
	
	  $("#upis").uploadify({
	       swf: _contextPath+'/common/uploadify/uploadify.swf',
	       uploader : contextPath+'/sys/upload.htm',
	       queueID: 'fileQueue',
	       auto: true,
	       fileObjName :'file',
	       buttonText: '选择发现问题图片',
	       multi : true,
	       queueSizeLimit: 10 ,
	       removeCompleted : true,
	       fileTypeExts: '*.jpg;*.gif;*.jpeg;*.png;*.bmp;',
	       onInit:function(obj){
	          
	       },
	       onUploadSuccess: function(file, data, response){
		       	var obj = JSON.parse(data); 
		      	$("#"+file.id).find("div.cancel>a").attr("href","javascript:onCancelWordPic('"+file.id+"','"+obj.id+"');");
	      		var fileObj  = {}
	      		
	      		if(obj.fileInDB){//上传并且入库成功
	      			//var s=$("#all_words1").val();
	      		var c = $("#ac").val();
	      			$("#em"+c).append( '<img rel="800:485" width="180" height="180" src="http://120.55.241.58/'+obj.filename+'">');
	      			$("#all_words"+c).val(obj.filename);				
	       	} else {
	       		alert("上传文件失败，请联系管理员");
	       	}
		       		
	       },
	       onError: function(event, queueID, fileObj) {
	           sAlert("文件:" + fileObj.name + "上传失败");
	       }
	       
	   });	
		  

	  $("#upis_solve").uploadify({
	       swf: _contextPath+'/common/uploadify/uploadify.swf',
	       uploader : contextPath+'/sys/upload.htm',
	       queueID: 'fileQueue',
	       auto: true,
	       fileObjName :'file',
	       buttonText: '选择解决问题图片',
	       multi : true,
	       queueSizeLimit: 10 ,
	       removeCompleted : true,
	       fileTypeExts: '*.jpg;*.gif;*.jpeg;*.png;*.bmp;',
	       onInit:function(obj){
	          
	       },
	       onUploadSuccess: function(file, data, response){
		       	var obj = JSON.parse(data); 
		      	$("#"+file.id).find("div.cancel>a").attr("href","javascript:onCancelWordPic('"+file.id+"','"+obj.id+"');");
	      		var fileObj  = {}
	      		
	      		if(obj.fileInDB){//上传并且入库成功
	      			
	      		var c = $("#ac").val();
	      			$("#sem"+c).append( '<img rel="800:485" width="180" height="109.125" src="http://120.55.241.58/'+obj.filename+'">');
	      			$("#solve_words"+c).val(obj.filename);				
	       	} else {
	       		alert("上传文件失败，请联系管理员");
	       	}
		       		
	       },
	       onError: function(event, queueID, fileObj) {
	           sAlert("文件:" + fileObj.name + "上传失败");
	       }
	       
	   });	
		  
});


function isNull( str ){
	if ( str == "" ) return true;
	var regu = "^[ ]+$";
	var re = new RegExp(regu);
	return re.test(str);
	}

var addInspection = function(){
	var id = $("#id").val();
	var inspection_time = $("#inspection_time").val();
	
	var bcount = $("#bcount").val();
	var bc = Number(bcount)
	if(bc>0 && countAry.length==1){
		count = bcount
		
		for (var j = 1;j<count; ){
			var tt = ++j
		
			countAry.push(tt);	
		}	
	}
	//获取发现问题照片路径
	var fupload = "";
	//获取解决问题照片路径
	var supload = "";
	//获取所有解决问题描述
	var solves = "";
	//获取所有发现问题描述
	var fs = "";
	//问题解决状态
	var state = "";
	//获取问题id
	var insp_ids = "";
	for (i in countAry){	
		
		if($("#solve_words"+countAry[i]).val() == ""){
			$("#solve_words"+countAry[i]).val(" ")  	
		}
		if($("#all_words"+countAry[i]).val() == ""){
			$("#all_words"+countAry[i]).val(" ")  	
		}
		if($("#psolve"+countAry[i]).val() == ""){
			$("#psolve"+countAry[i]).val(" ")  	
		}
		if($("#pfind"+countAry[i]).val() == ""){
			$("#pfind"+countAry[i]).val(" ")  	
		}
		fupload += "," +$("#all_words"+countAry[i]).val();
		supload += "," +$("#solve_words"+countAry[i]).val();
		solves += "," +$("#psolve"+countAry[i]).val();
		fs += "," +$("#pfind"+countAry[i]).val();
		insp_ids+= "," +$("#pid"+countAry[i]).val();
		var stateimp = "";
		/*
		if(($("#solve_words"+countAry[i]).val() == "" || $("#solve_words"+countAry[i]).val() == " ")&&( $("#psolve"+countAry[i]).val() == ""|| $("#psolve"+countAry[i]).val() == " ")){
			stateimp = "0";
		}else{
			stateimp = "1";
		}
		*/
		if((isNull($("#solve_words"+countAry[i]).val()) || isNull($("#solve_words"+countAry[i]).val()) )&&(isNull($("#psolve"+countAry[i]).val())||isNull($("#psolve"+countAry[i]).val()) )){
			stateimp = "0";
		}else{
			stateimp = "1";
		}
		state += ","+stateimp;
	}
	
	if (fupload == ","){
		fupload = ", "
	}
	if (supload == ","){
		supload = ", "
	}
	
	
	
	var center_id = $("#center_id").val();
	var problem_find = $("#p_find").val();
	var problem_solve = $("#problem_solve").val();
	var find_url = $("#all_words").val();
	var solve_url = $("#fw").val();
	
	if(inspection_time==""){
		infopad.err("请选择巡检日期!");
		return;
	}
	if(center_id==""){
		infopad.err("请选择巡检中心!");
		return;
	}
	
	
	$.post("${contextPath}/index/add_inspection.json", {
			"id":id,
			"inspection_time":inspection_time,
			"center_id":center_id,
			"problem_find":problem_find,
			"problem_solve":problem_solve,
			"fs":fs,
			"fupload":fupload,
			"solves":solves,
			"supload":supload,
			"state":state,
			"insp_ids":insp_ids
		}, function(ms) {
		    var msg = ms.msg;
		    if(msg!=null && msg=="1"){
				infopad.msg("操作成功！");
				window.location.href="${contextPath}/index/inspectionList.htm";

		    }else{
		    	infopad.err("操作失败，请联系管理员！");
		    }
			
	});
};



//删除图片
var deleteImg = function(id,img_index){
	$("#"+id).remove();
	var s=$("#all_words").val();
	s = s.replace(","+url,"");
	s = s.replace(url,"");
	$("#all_words").val(s);
};
var deleteImgfw = function(id,url){
	$("#"+id).remove();
	var s=$("#fw").val();
	s = s.replace(","+url,"");
	s = s.replace(url,"");
	$("#fw").val(s);
}
var count = 1
var countAry = [1];


	function add_tr() {
		//如果之前有值从之前的算起
		var  bcount = $("#bcount").val();
		var bc = Number(bcount)
		if(bc>0 && countAry.length==1){
			count = bcount
			
			for (var j = 1;j<count; ){
				var tt = ++j
				
				countAry.push(tt);	
			}	
		}
		//如果没有从1开始
		count++
		countAry.push(count)
		$("#firstO").nextAll().remove();
		//$("#ac").empty();
		for (i in countAry) {
			var tt = ++i;
			$("#ac").append("<option value="+i+">" + "事件" + tt + "</option>")
		}
		var tb = $("table").children(0);
		var cv = Number(count)
		var tr = tb.children("tr").eq(cv);

		var tr1 = tr.clone();
		var td = tr1.find("td")
		var th = tr1.find("th")
		th.html("问题" + count)
		td.each(function(index, element) {
			//td.children("div").
			//发现问题部分
			if (index == 0) {
				td.children("div").each(function(index,element){
				if(index == 0){
					var inp1 = $(this).find("em");
					var img = $(this).find("img")
					if(typeof(img)!="undefined"){ 

						   img.css('display','none')

						} 
					inp1.attr("id", "em" + count);
					var findtext = $(this).find("textArea");
					findtext.val(" ");
					findtext.attr("id","pfind"+count);
					var allword = $(this).find("input");
					allword.val(" ");
					allword.attr("id","all_words"+count);
				}else if(index == 1){
					
					var inp2 = $(this).find("em");
					var img = $(this).find("img")
					if(typeof(img)!="undefined"){ 

						   img.css('display','none')

						} 
					inp2.attr("id", "sem" + count);
					var solvetext = $(this).find("textArea");
					solvetext.val(" ");
					solvetext.attr("id","psolve"+count);
					var allword = $(this).find("input");
					allword.val(" ");
					allword.attr("id","solve_words"+count);	
				}
			})
				
			}else if (index == 1){
				
			}

		});
		
     
        
		tr.after(tr1);

	}
</script>
</head>
<input type="hidden" id="id" value="<#if inspection??>${inspection.id}</#if>">

<input type="hidden" id ="bcount" value="<#if inspPAry??>${inspPAry?size}</#if>">
<input type="hidden" id ="isScan" value="<#if isScan??>${isScan}</#if>">
				
<body>
	<div id="home_link">
		<ul>
			<li></li>
			<li>&gt;</li>
			<li>组织架构</li>
			<li>&gt;</li>
			<li class="current">title</li>
		</ul>
	</div>

	<div id="container">
		<div id="title">添加巡检</div>
		<table id="infotable">
			<tr>
				<th>巡检日期:</th>
				<td style="height:20px;">
					<input type="text" id="inspection_time" value="<#if inspection??>${inspection.inspection_time}</#if>" rel="DATE::Y-m-d" value="" size="15" maxlength="15" readonly="readonly" class="DatePicker_Icon">
				</td>
			</tr>
			
			<tr>
				<th>巡检中心:</th>
				<td>
				<select id="center_id">
					<option value="">请选择中心</option>
					<#if offList??>
						<#list offList as list>
							<option value="${list.id}">${list.name}</option>
						</#list>
					</#if>
				</select>
				</td>
				
			</tr>
			<#if inspPAry?? &&(inspPAry?size>0)>
			<#list inspPAry as inspP>
			<tr>
			<input type="hidden" id="pid${inspP_index + 1}" value="<#if inspP??>${inspP.id}</#if>">
			
				<th>问题${inspP_index + 1}</th>
				<td>
				
			
					<div style = "width :50%; float:left">
				
					
					
					<a class="file_box" style="list-style-type: none;float: left;display: block; width:180px; height:180px; overflow: hidden; border: 1px solid #EBEBEB; background: none repeat scroll 0 0 #F3F3F3; color: #999999; cursor: pointer; text-align: center; margin-left:10px; ">
                    <em id = "em${inspP_index + 1}" style="background:url(${staticServer}/img/add_newpic.png) 0 0; display: inline-block; width:180px; height:180px; overflow: hidden;line-height: 20em; vertical-align: middle;">
                   <#if inspP?? && inspP.find_url?? && inspP.find_url != ""&& inspP.find_url != " ">
                    <img rel="800:485" width="180" height="109.125" src="http://120.55.241.58/${inspP.find_url}">
                   </#if>
                    </em>
                    
                    </a>
                    		
                    	<textArea id="pfind${inspP_index + 1}" type="text" placeholder = "请填写发现问题描述"   style="width:180px;height:100px;" /><#if inspP?? && inspP.find_p?? >${inspP.find_p}</#if></textArea>
                    
                    <label class="zt_widthlabel" style=" font-size:9px; float:left; visibility:hidden;">文件：</label>
                    <input type="text" id="all_words${inspP_index + 1}" value="<#if inspP??>${inspP.find_url}</#if>" style=" width:100px; height:10px; float:left;visibility:hidden;" class="input w180" value="">
				</div>
				
				<div style = "width:50%; float:left">
				
					
					
					<a class="file_box" style="list-style-type: none;float: left;display: block; width:180px; height:180px; overflow: hidden; border: 1px solid #EBEBEB; background: none repeat scroll 0 0 #F3F3F3; color: #999999; cursor: pointer; text-align: center; margin-left:10px; ">
                    <em id = "sem${inspP_index + 1}" style="background:url(${staticServer}/img/add_newpic.png) 0 0; display: inline-block; width:180px; height:180px; overflow: hidden;line-height: 20em; vertical-align: middle;">
                    <#if inspP?? && inspP.solve_url?? && inspP.solve_url != " "&& inspP.solve_url != "">
                    <img rel="800:485" width="180" height="109.125" src="http://120.55.241.58/${inspP.solve_url}">
                   </#if>
                    </em>
                    </a>
                    						
                 	<textArea id="psolve${inspP_index + 1}" placeholder = "请填写解决问题描述" type="text" style="width:180px;height:100px;" /> <#if inspP?? && inspP.solve_p?? >${inspP.solve_p}</#if></textArea>
                    
                    <label class="zt_widthlabel" style=" font-size:9px; float:left; visibility:hidden;">文件：</label>
                   
                    <input type="text" id="solve_words${inspP_index + 1}" value="<#if inspP??>${inspP.solve_url}</#if>" style=" width:100px; height:10px; float:left;visibility:hidden;" class="input w180" value="">
                   
				</div>
			
				</td>
			
			</tr>
</#list>
			<#else>
		
		
			<tr>
			
				<th>问题1</th>
				<td>
				
			
					<div style = "width :50%; float:left">
				
					
					
					<a class="file_box" style="list-style-type: none;float: left;display: block; width:180px; height:180px; overflow: hidden; border: 1px solid #EBEBEB; background: none repeat scroll 0 0 #F3F3F3; color: #999999; cursor: pointer; text-align: center; margin-left:10px; ">
                    <em id = "em1" style="background:url(${staticServer}/img/add_newpic.png) 0 0; display: inline-block; width:180px; height:180px; overflow: hidden;line-height: 20em; vertical-align: middle;">
                  
                    </em>
                    
                    </a>
                    		
                    	<textArea id="pfind1" type="text" placeholder = "请填写发现问题描述" style="width:180px;height:100px;" /></textArea>
                    
                    <label class="zt_widthlabel" style=" font-size:9px; float:left; visibility:hidden;">文件：</label>
                    <input type="text" id="all_words1" value="<#if inspP??>${inspP.find_url}</#if>" style=" width:100px; height:10px; float:left;visibility:hidden;" class="input w180" value="">
				</div>
				
				<div style = "width:50%; float:left">
				
					
					
					<a class="file_box" style="list-style-type: none;float: left;display: block; width:180px; height:180px; overflow: hidden; border: 1px solid #EBEBEB; background: none repeat scroll 0 0 #F3F3F3; color: #999999; cursor: pointer; text-align: center; margin-left:10px; ">
                    <em id = "sem1" style="background:url(${staticServer}/img/add_newpic.png) 0 0; display: inline-block; width:180px; height:180px; overflow: hidden;line-height: 20em; vertical-align: middle;">
                   
                    </em>
                    </a>
                    						
                 	<textArea id="psolve1" placeholder = "请填写解决问题描述" type="text" style="width:180px;height:100px;" /></textArea>
                    
                    <label class="zt_widthlabel" style=" font-size:9px; float:left; visibility:hidden;">文件：</label>
                    <img alt="" src="">
                    <input type="text" id="solve_words1" value="<#if inspP??>${inspP.solve_url}</#if>" style=" width:100px; height:10px; float:left;visibility:hidden;" class="input w180" value="">
                   
				</div>
			
				</td>
			
			</tr>
		
			
		</#if>
		
		</table>
	<div id = "foot">
		
		&nbsp	<button onclick = "add_tr()">添加问题 </button></br></br>
			<select id= "ac">
			<option id = "firstO" value="">请选择问题条目</option>
			<option  value="1">问题1</option>
			</select>
		<input type="file"  id="upis"  style="width:180px; height:80px; ">
		
		<input type="file"  id="upis_solve"  style="width:180px; height:80px; ">
			
			
		<div id="controlbar">
			<input type="button" class="submit" onclick="addInspection()" value="  提交保 存  " />
		</div>
		</div>
	</div>
	
</body>
</html>